<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net 
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : complaint.manage.php   FILE_PATH : E:\web\mulitishop\system\complaint.manage.php
 * 投诉/举报管理
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 大白菜芯 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Thu Nov 08 17:24:37 CST 2007
 */

require_once("../global.inc.php");

class SysComplaintManage extends SystemFrameWork{
	/**
	 * 投诉举报对象
	 *
	 * @var obj
	 */
	var $objcomplaint;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;
	/**
	 * 商品对象
	 *
	 * @var obj
	 */
	var $obj_product;
	/**
	 * 会员对象
	 *
	 * @var obj
	 */
	var $obj_member;
	/**
	 * 商品交易对象
	 *
	 * @var obj
	 */
	var $obj_product_order;
	/**
	 * 网站提醒对象
	 *
	 * @var obj
	 */
	var $obj_remind;
	
	function main(){
		/**
		 * 创建投诉举报对象
		 */
		if (!is_object($this->objcomplaint)){
			require_once("complaint.class.php");
			$this->objcomplaint = new Complaint();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}
		/**
		 * 创建商品对象
		 */
		if (!is_object($this->obj_product)){
			require_once("product.class.php");
			$this->obj_product = new ProductClass();
		}
		/**
		 * 创建会员对象
		 */
		if (!is_object($this->obj_member)){
			require_once("member.class.php");
			$this->obj_member = new MemberClass();
		}
		/**
		 * 创建商品订单对象
		 */
		require_once("order.class.php");
		if (!is_object($this->obj_product_order)){
			$this->obj_product_order = new ProductOrderClass();
		}
		
		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("system");

		/**
		 * 语言包
		 */
		$this->getlang("complaint");

		switch ($this->_input['action']){
			case "add_msg":
				$this->_add_msg();
				break;
			case "save_msg":
				$this->_save_msg();
				break;
			case "handling":
				$this->_handling_complaint();
				break;
			case "modify_handling":
				$this->_modify_handling_complaint();
				break;
			case "view":
				$this->_view_complaint();
				break;
			case "del":
				$this->_del_complaint();
				break;
			default:
				$this->_list_complaint();
				break;
		}
	}
	
	/**
	 * 投诉举报信息列表
	 */
	function _list_complaint(){
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();
		
		$condition_array = array('class'=>$this->_input['complaint_report'],'type'=>$this->_input['type'],'date'=>'history');
		$obj_page->pagebarnum(10);
		$complaint_receive_list = $this->objcomplaint->getComplaintList($condition_array,$obj_page);
		if (is_array($complaint_receive_list)){
			foreach ($complaint_receive_list as $key => $value){
				if ($value['c_r_type'] == 12){
					$product_row = $this->obj_product->getProductRow($value['c_r_related_product']);
					$complaint_receive_list[$key]['c_r_related_name'] = $product_row['p_name'];
				}
			}
		}
		$page_list = $obj_page->show(1);
		
		/**
		 * 模板输出
		 */
		$this->output("type", $this->_input['type']);/*选择类别*/
		$this->output("complaint_report_type", $this->_b_config['complaint_report_type']);/*投诉举报类别*/
		$this->output("baseconfig_handling", $this->_b_config['complaint_report_handling']);/*投诉举报处理状态*/
		$this->output("complaint_receive_list", $complaint_receive_list);/*投诉举报信息列表*/
		$this->output("page_list", $page_list);/*分页*/
		$this->output("complaint_report", $this->_input['complaint_report']);/*投诉或者举报列表*/
		if ($this->_input['complaint_report'] == 'complaint' || $this->_input['complaint_report'] == 'sell' || $this->_input['complaint_report'] == 'buy'){
			$this->showpage('sys_complaint_complaint.manage');
		}elseif ($this->_input['complaint_report'] == 'report') {
			$this->showpage('sys_complaint_report.manage');
		}
	}
	
	/**
	 * 查看投诉举报信息
	 */
	function _view_complaint(){
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();
		
		/*取信息内容*/
		$complaint_array = $this->objcomplaint->getComplaintById($this->_input['complaint_report_id']);
		if ($complaint_array['c_r_type'] == 10){
			$this->output('embargo_id',$this->_b_config['complaint_report_prohibited_product'][$complaint_array['embargo_id']]);/*禁售品*/
		}
		if ($complaint_array['c_r_type'] == 12){
			/**
			 * 取重复铺货商品信息
			 */
			$product_row = $this->obj_product->getProductRow($complaint_array['c_r_related_product']);
			$complaint_array['c_r_related_product_name'] = $product_row['p_name']; 
		}
		
		
		/*取系统回复留言内容*/
		$obj_page->pagebarnum(10);
		$msg_array = $this->objcomplaint->getComplaintMsgById($this->_input['complaint_report_id'],$complaint_array['c_r_class'],$obj_page);
		$page_list = $obj_page->show(1);
		
		/**
		 * 模板输出
		 */
		
		$this->output("complaint_report_type", $this->_b_config['complaint_report_type']);/*投诉举报类别*/
		$this->output("baseconfig_handling", $this->_b_config['complaint_report_handling']);/*投诉举报处理状态*/
		$this->output('complaint_array',$complaint_array);
		$this->output('msg_array',$msg_array);
		$this->output("page_list", $page_list);/*分页*/
		$this->output("complaint_report", $this->_input['complaint_report']);/*投诉或者举报列表*/
		if ($this->_input['complaint_report'] == 'complaint' || $this->_input['complaint_report'] == 'sell' || $this->_input['complaint_report'] == 'buy'){
			$this->showpage('sys_complaint_complaint.view');
		}elseif ($this->_input['complaint_report'] == 'report') {
			$this->showpage('sys_complaint_report.view');
		}
	}
	
	/**
	 * 对举报投诉进行留言
	 */
	function _add_msg(){
		
		$this->output("complaint_report", $this->_input['complaint_report']);/*投诉或者举报标识*/
		$this->output('complaint_report_id',$this->_input['complaint_report_id']);
		$this->showpage('sys_complaint_msg.add');
	}
	
	/**
	 * 添加留言
	 */
	function _save_msg(){
		
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["r_c_content"],"require"=>"true","message"=>$this->_lang['errMsgNoContent']));/*留言内容*/
		$error = $this->objvalidate->validate();

		if($error != ""){
			echo $error;
			exit;
		}
		/*取投诉举报信息内容*/
		$complaint_array = $this->objcomplaint->getComplaintById($this->_input['complaint_report_id']);

		/*添加*/
		$value_array = array();
		if ($complaint_array['c_r_class'] == 1 || $complaint_array['c_r_class'] == 2){
			$value_array['r_c_msg_type'] = 0;
		}elseif ($complaint_array['c_r_class'] == 3 || $complaint_array['c_r_class'] == 4){
			$value_array['r_c_msg_type'] = 1;
		}
		$value_array['complaint_report_id'] = $this->_input['complaint_report_id'];
		$value_array['r_c_msg_add'] = time();
		$value_array['r_c_content'] = $this->_input["r_c_content"];
		
		$this->objcomplaint->addComplaintMsg($value_array);
		$this->redirectPath("succ","system/complaint.manage.php?action=view&complaint_report=" . $this->_input['complaint_report'] . "&complaint_report_id=".$this->_input['complaint_report_id'],"提交成功！");
	}
	
	/**
	 * 对投诉举报信息进行处理
	 */
	function _handling_complaint(){
		
		$this->output("complaint_report", $this->_input['complaint_report']);/*投诉或者举报标识*/
		$this->output('complaint_report_id',$this->_input['complaint_report_id']);
		$this->showpage('sys_complaint.handling');
	}
	
	/**
	 * 保存举报投诉处理信息
	 */
	function _modify_handling_complaint(){
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["result"],"require"=>"true","message"=>$this->_lang['errMsgNoContent']));/*处理结果*/
		$error = $this->objvalidate->validate();

		if($error != ""){
			echo $error;
			exit;
		}
		
		/*取投诉举报信息内容*/
		$complaint_array = $this->objcomplaint->getComplaintById($this->_input['complaint_report_id']);

		$value_array = array();
		$value_array['complaint_report_id'] = $this->_input['complaint_report_id'];/*信息ID*/
		if ($complaint_array['c_r_handling_state'] == 0){
			/*添加一条留言信息*/
			$value_array = array();
			if ($complaint_array['c_r_class'] == 1 || $complaint_array['c_r_class'] == 2){
				$value_array['r_c_msg_type'] = 0;
			}elseif ($complaint_array['c_r_class'] == 3 || $complaint_array['c_r_class'] == 4){
				$value_array['r_c_msg_type'] = 1;
			}
			$value_array['complaint_report_id'] = $complaint_array['complaint_report_id'];
			$value_array['r_c_msg_add'] = time();
			$value_array['r_c_content'] = $this->_input["result"];
			$this->objcomplaint->addComplaintMsg($value_array);
			/*更改投诉举报信息的状态*/
			$value_array['c_r_handling_state'] = 1;/*处理状态*/
		}else {
			$value_array['c_r_result'] = $this->_input['result'];/*处理结果*/
			$value_array['c_r_end_time'] = time();/*处理结束时间*/
			$value_array['c_r_handling_state'] = 3;/*处理状态*/
		}

		$this->objcomplaint->updateComplaintById($value_array);
		
		/**
		 * 网站提醒操作
		 */
		if (!is_object($this->obj_remind)){
			require_once('remind.class.php');
			$this->obj_remind = new RemindClass();
		}
		/*提醒发起举报者*/
		$value_array = array();
		$value_array['username'] = $complaint_array['login_name'];
		$this->obj_remind->setMessageOrMail('complaint_handling_notice','complaint_handling_notice',$value_array,$complaint_member['login_name'],$this->_configinfo);
		/*提醒被起举报者*/
		$value_array = array();
		$value_array['username'] = $complaint_array['c_r_login_name'];
		$this->obj_remind->setMessageOrMail('complaint_handling_notice','complaint_handling_notice',$value_array,$complaint_member['login_name'],$this->_configinfo);
		
		
		$this->redirectPath("succ","system/complaint.manage.php?action=view&complaint_report=" . $this->_input['complaint_report'] . "&complaint_report_id=".$this->_input['complaint_report_id'],"提交成功！");
	}
	
	/**
	 * 删除投诉/举报信息
	 */
	function _del_complaint(){
		
		$id = $this->_input['complaint_report_id'];
		
		$this->objcomplaint->delComplaintById($id);
		$this->redirectPath("succ","system/complaint.manage.php?complaint_report=".$this->_input['complaint_report'],"提交成功！");
	}
	
}

$complaint_manage = new SysComplaintManage();
$complaint_manage->main();
unset($complaint_manage);
?>